package com.talent.controller;

import com.talent.common.PageResult;
import com.talent.common.Result;
import com.talent.pojo.entity.OperationLog;
import com.talent.service.OperationLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * 操作日志控制器
 */
@RestController
@RequestMapping("/api/logs")
@Slf4j
public class OperationLogController {

    @Autowired
    private OperationLogService operationLogService;

    /**
     * 分页查询操作日志
     */
    @GetMapping
    public Result<PageResult<OperationLog>> pageQuery(@RequestParam(defaultValue = "1") Integer page,
                                                      @RequestParam(defaultValue = "10") Integer pageSize,
                                                      String username,
                                                      String phone,
                                                      String action,
                                                      @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
                                                      @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
        log.info("分页查询操作日志：page={}, pageSize={}, username={}, phone={}, action={}, startDate={}, endDate={}", 
                page, pageSize, username, phone, action, startDate, endDate);
        
        PageResult<OperationLog> pageResult = operationLogService.pageQuery(
                page, pageSize, username, phone, action, startDate, endDate);
        return Result.success(pageResult);
    }
}
